package com.hongning.railway.ui.main.fragments.cadremanagement;

import android.app.Application;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.support.annotation.NonNull;

import com.hongning.railway.R;
import com.hongning.railway.data.AppRepository;
import com.hongning.railway.entity.reqbean.ReqKaoHeBaseBean;
import com.hongning.railway.entity.reqbean.ReqKaoHeListBean;
import com.hongning.railway.entity.resbean.ResKaoHeListBean;
import com.hongning.railway.ui.main.fragments.cadremanagement.viewmodel.CadreReslutFragmentItemViewModel;
import com.hongning.railway.util.Apputils;

import java.util.List;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.http.ApiDisposableObserver;
import me.goldze.mvvmhabit.utils.RxUtils;
import me.tatarka.bindingcollectionadapter2.BR;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class CadreReslutFragmentViewModel extends BaseViewModel<AppRepository> {
    public ItemBinding<CadreReslutFragmentItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_cadre_result);
    public ObservableList<CadreReslutFragmentItemViewModel> items = new ObservableArrayList<>();
    public CadreReslutFragmentViewModel(@NonNull Application application) {
        super(application);
    }

    public CadreReslutFragmentViewModel(@NonNull Application application, AppRepository model) {
        super(application, model);
    }

    public void loadData(String id){
        ReqKaoHeBaseBean reqKaoHeListBean = new ReqKaoHeBaseBean();
        reqKaoHeListBean.setStaffId(Apputils.getStaffid());
        reqKaoHeListBean.setTestinfoid(id);

        model.selectTestScoreAPP(reqKaoHeListBean)
                .compose(RxUtils.bindToLifecycle(getLifecycleProvider()))
                .compose(RxUtils.schedulersTransformer())
                .subscribe(new ApiDisposableObserver<ResKaoHeListBean>() {
                    @Override
                    public void onResult(ResKaoHeListBean resKaoHeListBean) {
                        List<ResKaoHeListBean.DataBean> dataBeans= resKaoHeListBean.getData();
                        for (ResKaoHeListBean.DataBean data:dataBeans) {
                            items.add(new CadreReslutFragmentItemViewModel(CadreReslutFragmentViewModel.this,data));
                        }
                    }
                });
    }
}
